home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-13
/
me_cd22.zip
/
MUTT2.ZIP
/
PMATCH.MUT
< prev
next >
Wrap
Text File
|
1992-04-27
|
2KB
|
73 lines
;; pmatch.mut : paren matcher. Works on (){}
;; Put the cursor at a paren, execute p-match. The cursor is moved to the
;; matching paren, sits there for a while so you can see the matching
;; paren and then curor is restored. The mark is left at the matching
;; paren so you can (exchange-dot-and-mark) at your convience.
;; C Durland Public Domain
(const DELAY 3) ; Number of seconds to show the matching paren
(defun
p-match-forward (open-paren close-paren) HIDDEN
{
(string m)(int c)
(c 1)
(next-character)(m (concat "[" open-paren close-paren "]"))
(while (!= c 0)
{
(if (key-waiting) { (get-key) FALSE (done) }) ; let user interrupt
(if (re-search-forward m) () { FALSE (done) })
(switch (get-matched "&")
open-paren (+= c 1)
close-paren (c (- c 1))
)
; (update) ; these are fun to watch
})
(previous-character)
TRUE
}
p-match-backward (open-paren close-paren) HIDDEN
{
(string m)(int c)
(c 1)
(m (concat "[" open-paren close-paren "]"))
(while (!= c 0)
{
(if (key-waiting) {(get-key)(FALSE)(done)}) ; let user interrupt
(if (re-search-reverse m) () { FALSE (done) })
(switch (get-matched "&")
open-paren (+= c 1)
close-paren (c (- c 1))
)
(update) ; these are fun to watch
})
TRUE
}
p-match
{
(string op)(int c)
(if (looking-at ".") () { (msg "Can't match that!")(done) })
(set-mark)(msg "Looking ...")
(switch (op (get-matched "&"))
"(" (p-match-forward "(" ")")
"{" (p-match-forward "{" "}")
"}" (p-match-backward "}" "{")
")" (p-match-backward ")" "(")
default { (msg "Can't match that!")(done) }
)
(if ()
{
(msg "Here's the matching paren")
(update) ; show matching paren
(key-waiting DELAY) ; wait a little bit
(msg "Mark is at matching paren")
}
(msg "Unbalanced \"" op "\"")
)
(swap-marks)
}
)